package coreconcurrency.mem;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * create by yongli on 2022-04-19 09:21
 */

public class MultiThread extends Thread {

    Logger logger = LoggerFactory.getLogger(MultiThread.class);


    // 线程的变量
    private Computer computer;
    private long delay=0;

    public MultiThread(Computer computer,long delay) {
        this.computer = computer;
        this.delay = delay;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(delay);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // sout是一个同步方法，不用于测试多线程
        logger.info("{}--- {}",delay,computer.getNums());
        logger.info("{}",computer.getName());
        logger.info(computer.getScreen().toString());

        int[] arr = {12,3,2,13,3,55,34};
        // 改变了对象，会不会刷新到主存，被其他线程感知？
        computer.setNums(arr);
        computer.setScreen(new Screen(120,100));
        computer.setName("America");
        // sout是一个同步方法，不用于测试多线程
//        logger.info("{}--{}",delay,computer.getNums());
//        logger.info("{}",computer.getName());
//        logger.info(computer.getScreen().toString());

        // 线程等待，不结束
        int i=10;

        while (true){
            i++;
            double n =10000000000000d;
            double m  = n/12121.012;
            double k = m*1222.333;
            double k1 = k/ 882.3;

        }

    }

    public Computer getComputer() {
        return this.computer;
    }
}
